package day20.pack3;

import lombok.SneakyThrows;

public class Counter {
    private int count;
    @SneakyThrows
    public synchronized void increment() {
        String name = Thread.currentThread().getName();
        while("B".equals(name) && count % 2 == 0) {
            this.wait();
        }
        while("A".equals(name) && count % 2 == 1) {
            this.wait();
        }
        count++;
        System.out.println(name + ":" + count);
        this.notify();
    }
}
